﻿using System;
using System.CodeDom.Compiler;
using System.Linq;

namespace FBGraph.ClientGenerator.CodeGen
{
    public class XmlDocCommentList : CodeGenObjectList<XmlDocComment>
    {
        private const String SUMMARY_OPEN_TAG = "<summary>";
        private const String SUMMARY_EMPTY = "<summary></summary>";

        public XmlDocCommentList(params XmlDocComment[] comments) : base(comments) { }
        public XmlDocCommentList(params String[] comments) : this(comments.Select(c => new XmlDocComment(c)).ToArray()) { }
        public XmlDocCommentList() { }

        public override void Write(CodeGenWriter writer)
        {
            base.Write(writer);
        }

        public void Suggest(String comment)
        {
            Suggest(new XmlDocComment(comment));
        }

        public void Suggest(String comment, params Object[] args)
        {
            Suggest(new XmlDocComment(comment, args));
        }

        public void Suggest(XmlDocComment item)
        {
            if (!this.Any(i => i.Text == item.Text) && item.Text != SUMMARY_EMPTY)
            {
                if (item.Text.StartsWith(SUMMARY_OPEN_TAG))
                {
                    if (!this.Any(i => i.Text.StartsWith(SUMMARY_OPEN_TAG))) this.Add(item);
                }
                else this.Add(item);
            }
        }
    }
}